package com.example.fragmenttest.fragment;

import android.content.Context;
import android.os.Bundle;
import android.util.Log;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;

import androidx.annotation.NonNull;
import androidx.annotation.Nullable;
import androidx.fragment.app.Fragment;
import androidx.lifecycle.MutableLiveData;

import com.example.fragmenttest.R;
import com.example.fragmenttest.communication.CommunicationInterface;

// Fragment部分代码
public class MyFragment extends Fragment {
    private CommunicationInterface communicator;


    @Override
    public void onCreate(@Nullable Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);

        new MutableLiveData<>();
        // 获取传递过来的参数
        if (getArguments() != null) {
            String userName = getArguments().getString("user_name");
            // 这里可以根据userName做一些处理，例如更新界面显示等
            Log.d("userName", "onCreate: " + userName);
        }
    }

    @Nullable
    @Override
    public View onCreateView(@NonNull LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) {
        super.onCreateView(inflater, container, savedInstanceState);

        return inflater.inflate(R.layout.my_fragment, container, false);
    }

    @Override
    public void onAttach(Context context) {
        super.onAttach(context);
        communicator = (CommunicationInterface) context;
    }

    public void sendToActivity(Bundle data) {
        communicator.sendDataToActivity(data);
    }
}